/*=========================================================================================================================/
 * 
 * FILE: HomeboundGame.cs
 * AUTH: Matthew Baum
 * DATE: 10/28/2011
 * CHANGE: 11/27/2011
 * 
 * ADDED:
 *          - Seperate drawing (different sprite batches) for HUD and BG, to supprot BG layers & parralax
 *          - Additional HUD data
 *          - Added content loading for energy cells
 * 
 *========================================================================================================================
 *
 * BASED ON:
 * 
 *-----------------------------------------------------------------------------
 * PlatformerGame.cs
 *
 * Microsoft XNA Community Game Platform
 * Copyright (C) Microsoft Corporation. All rights reserved.
*-----------------------------------------------------------------------------*/


using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Input.Touch;


namespace Homebound
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class HomeboundGame : Microsoft.Xna.Framework.Game
    {
        // Resources for drawing.
        private GraphicsDeviceManager graphics;
        private SpriteBatch spriteBatch;

        // Global content.
        private SpriteFont hudFont;
        private SpriteFont titleFont;
        private SpriteFont choiceFont;
        //public SpriteFont scrollFont;

       
        // Alex: Game state management.
        StateManager stateManager;

        public HomeboundGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            GameServiceContainer test = Services;

            Accelerometer.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load fonts
            hudFont = Content.Load<SpriteFont>("Fonts/Hud");

            // Alex: Title, Choice font
            titleFont = Content.Load<SpriteFont>("Fonts/Title");
            choiceFont = Content.Load<SpriteFont>("Fonts/Choice");

            // Bachir: scrolling Text Font
            //scrollFont = Content.Load<SpriteFont>("Fonts/Scroll");

            // Intialize the state manager.
            stateManager = new StateManager(graphics, hudFont, choiceFont, hudFont, Services, Content);

            // Init Energy cells for the game
            EnergyCell.loadContent(Content);
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Pass control to the state manager.
            // Process input.
            stateManager.input(gameTime);
            
            // Update the game state.
            stateManager.update(gameTime);

            base.Update(gameTime);
        }

        /// <summary>
        /// Draws the game from background to foreground.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            // Commented out to enable separate drawing of backgrounds and HUD
            //spriteBatch.Begin();

            stateManager.draw(spriteBatch, gameTime);

            //spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}
